package testView;

import static org.junit.Assert.*;

import org.junit.Test;

import model.ClassImpl;
import model.AttributeImpl;
import model.OperationImpl;
/**
*   @version Iteration 3 March 21, 2011
*	@author Team EBE
*	CSCI 420 UML Diagram Software Engineering Project
*
*	Tests the ClassImpl.java, AttributeImpl.java and OpeartionImpl.java Models
*	Specifically, this tests the construction of a new class, 
*	setting size, resizing, and adding attributes and operations
*	to populate the class. 
*/

public class testClass {

/**
 * 	This method tests the ClassImpl class. 
 * 	This test initializes a new class by giving it 
 * 	a name and setting the weight and width to a default
 * 	of 5. It also sets the origins that the user specifies.
 */
	@Test
	public void testClass(){
		ClassImpl testClass = new ClassImpl();
		String name = "Test Main";
		int sizeX = 5;
		int sizeY = 5;
		
		//initializes the name, x and y coordinate to the sizex and sizey
		testClass.getName();
		testClass.setWidth(sizeX);
		testClass.setHeight(sizeY);
		
		//test the functions that give you the name, x size, and y size, and origins
		testClass.getName();	
		testClass.getWidth();
		testClass.getHeight();
		testClass.getoX();
		testClass.getoY();
		
		//Assert Tests
		assertEquals(testClass.getWidth(), 5);
		assertEquals(testClass.getHeight(), 5);
		assertEquals(testClass.getoX(), 0);
		assertEquals(testClass.getoY(), 0);
	}
	
/**
 * 	This method tests the Class Attributes class. 
 * 	Specifically, it verifies that the user specified
 * 	additions are adding in correctly. It also ensures
 * 	that adding a new attribute does not overwrite an 
 * 	older attribute. 
 */
	@Test
	public void testClassAttributes(){
		ClassImpl tClass = new ClassImpl("Test");
		int vecVal = 0;
		String testString = "c a : b";
		String testString1 = "z x : y";
		
		//adds attribute and verifies it has been correctly added
		tClass.addAttribute("a", "b", 'c');
		assertEquals(tClass.getAttributes().elementAt(vecVal).toString(), testString);
		
		//adds another attribute and verifies it has been correctly added and hasn't overwritten the first attribute
		tClass.addAttribute("x", "y", 'z');
		vecVal++;
		assertEquals(tClass.getAttributes().elementAt(vecVal-1).toString(), testString);
		assertEquals(tClass.getAttributes().elementAt(vecVal).toString(), testString1);
	}

/**
 * 	This method tests the Class Opeartions class. 
 * 	It is similar to the Class Attribute class in that
 *  it verifies that the user specified additions are 
 *  added in correctly. It also ensures that adding a 
 *  new operation does not overwrite an older attribute. 
 */
	@Test
	public void testClassOperations(){
		ClassImpl tClass1 = new ClassImpl("Test");
		String tString = "z x() : y";
		String tString1 = "c a() : b";
		int vecVal = 0;
		
		//adds operation and correctly verifies its insertion
		tClass1.addOperation("x", "y", 'z');
		assertEquals(tClass1.getOperations().elementAt(vecVal).toString(), tString);
		
		//adds another operation and verifies it has been correctly added and hasn't overwritten the first attribute
		tClass1.addOperation("a", "b", 'c');
		vecVal++;
		assertEquals(tClass1.getOperations().elementAt(vecVal-1).toString(), tString);
		assertEquals(tClass1.getOperations().elementAt(vecVal).toString(), tString1);
	}
	
/**
 * 	This method tests the saveString Method.
 *  It helps to prove that the data the user expects
 *  to be saved in a string is saved correctly.
 */
	public void testSaveStringMethod(){
		ClassImpl saveClass = new ClassImpl("SaveMe");
		
		saveClass.setHeight(5);
		saveClass.setWidth(10);
		saveClass.addOperation("x", "y", 'z');
		saveClass.addAttribute("1", "2", '3');
		saveClass.setoX(0);
		saveClass.setoY(0);
		String testCase = "saveClass\n1 1\n0 0 5 10\nz x y\n3 1 2\n";
		assertEquals(saveClass.saveString(), testCase);
	}
}
